import 'package:flutter/material.dart';
import 'package:website.core/core/presentation/theme/theme.dart';

part 'styles.dart';

part 'text_theme.dart';

class PurchaseManagementFragmentTheme extends InheritedTheme {
  PurchaseManagementFragmentTheme({
    required Brightness brightness,
    required Color primaryContrastingColor,
    required Widget child,
    Key? key,
  })  : _brightness = brightness,
        _primaryContrastingColor = primaryContrastingColor,
        _data = _buildThemeData(
          brightness: brightness,
          primaryContrastingColor: primaryContrastingColor,
        ),
        super(
          key: key,
          child: child,
        );

  final Brightness _brightness;
  final Color _primaryContrastingColor;
  final PurchaseManagementFragmentThemeData _data;

  static PurchaseManagementFragmentThemeData _buildThemeData({
    required Brightness brightness,
    required Color primaryContrastingColor,
  }) {
    return PurchaseManagementFragmentThemeData.dark(
      primaryContrastingColor: primaryContrastingColor,
    );
  }

  static PurchaseManagementFragmentThemeData of(BuildContext context) {
    final inheritedTheme =
        context.dependOnInheritedWidgetOfExactType<PurchaseManagementFragmentTheme>()!;
    return inheritedTheme._data;
  }

  @override
  Widget wrap(BuildContext context, Widget child) {
    final ancestorTheme = context.findAncestorWidgetOfExactType<PurchaseManagementFragmentTheme>();

    if (identical(this, ancestorTheme)) {
      return child;
    }

    return PurchaseManagementFragmentTheme(
      brightness: _brightness,
      primaryContrastingColor: _primaryContrastingColor,
      child: child,
    );
  }

  @override
  bool updateShouldNotify(PurchaseManagementFragmentTheme oldWidget) {
    return _brightness != oldWidget._brightness ||
        _primaryContrastingColor != oldWidget._primaryContrastingColor;
  }
}

class PurchaseManagementFragmentThemeData {
  const PurchaseManagementFragmentThemeData._internal({
    required this.dividerColor,
    required this.textTheme,
  });

  factory PurchaseManagementFragmentThemeData.dark({
    required Color primaryContrastingColor,
  }) {
    return PurchaseManagementFragmentThemeData._internal(
      dividerColor: CoreStyles.darkGrey2,
      textTheme: PurchaseManagementFragmentTextTheme.dark(
        primaryContrastingColor: primaryContrastingColor,
      ),
    );
  }

  final Color dividerColor;
  final PurchaseManagementFragmentTextTheme textTheme;
}
